package com.bjpowernode.service.impl;

import com.bjpowernode.mapper.AdminMapper;
import com.bjpowernode.pojo.Admin;
import com.bjpowernode.pojo.AdminExample;
import com.bjpowernode.service.AdminService;
import com.bjpowernode.utils.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class AdminServiceImpl implements AdminService {

    //在业务层逻辑中，一定会有数据访问层的对象
    @Autowired
    AdminMapper adminMapper;


    @Override
    public Admin login(String name, String pwd) {

        //根据用户名到DB中查询相应的对象
            //如果有条件则一定要创建AdminExample的对象，用来封装条件
        AdminExample example = new AdminExample();
        //如何添加条件：select * from admin where a_name="aname"

        //添加用户名a_name条件
        example.createCriteria().andANameEqualTo(name);

        List<Admin> list = adminMapper.selectByExample(example);

        if(list.size()>0){
            Admin admin = list.get(0);
            //如果查到用户对象在进行密码的比对,注意使用MD5加密后再与数据库中用户密码比较
            String mipwd = MD5Util.getMD5(pwd);
            String s = admin.getaPass();
            if (s.equals(mipwd)){
                return admin;
            }

        }



        return null;
    }
}
